#ifndef ZLOG_MANAGER_H_
#define ZLOG_MANAGER_H_

#include "../Common/GlobalDefines.h"
#include "../Common/ZSingleton.h"
#include "ZLog.h"
#include <map>

GLOBAL_NAMESPACE_BEGIN

class LogManager : public Singleton < LogManager >
{
protected:
	typedef std::map<std::string, Log*> LogList;

    LogList     logs_;
    Log         *pDefaultLog_;

public:
    LogManager();
    ~LogManager();

    Log* createLog(const std::string& name, const std::string& fileName, bool defaultLog = false, bool debuggerOuput = true);
    Log* getLog(const std::string& name);
    Log* getDefaultLog();

    void destroyLog(const std::string& name);
    void destroyLog(Log* log);

    // the returned log is the old default log
    Log* setDefaultLog(Log* newLog);

    // Log a message to the default log
    void logMessage(const std::string& message, LogLevel level = LOGLEVEL_NORMAL, bool maskDebug = false);

    Log::Stream stream(LogLevel level = LOGLEVEL_NORMAL, bool maskDebug = false);

    static LogManager& getSingleton(void);
    static LogManager* getSingletonPtr(void);

private:
    void destroy();
};

#define ZLOG(name, level, maskDebug)  ZFramework::LogManager::getSingleton().getLog(name)->stream(level, maskDebug)
#define DebugLog                ZLOG(std::string("Debug"), ZFramework::LOGLEVEL_DEBUG, false)
#define DefaultLog              ZLOG(std::string("Default"), ZFramework::LOGLEVEL_NORMAL, true)

GLOBAL_NAMESPACE_END

#endif//ZLOG_MANAGER_H_